package br.com.webhomesites.padrao.presenter;

import br.com.webhomesites.padrao.model.ClienteDAO;
import br.com.webhomesites.padrao.view.BuscarClienteView;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

public class BuscarClientePresenterActionListeners {
    
    static class BuscarFocusListener implements FocusListener {
        
        private BuscarClientePresenter presenter;
        private BuscarClienteView buscarClienteView;
        
        public BuscarFocusListener(BuscarClientePresenter presenter) {
            this.presenter = presenter;
            buscarClienteView = presenter.getBuscarClienteView();
        }
        
        @Override
        public void focusGained(FocusEvent e) {
            ClienteDAO clienteDAO = new ClienteDAO();
            if (e.getSource() == presenter.getBuscarClienteView().getComboCodigoJCombo()) {
                
                if (presenter.getBuscador() == presenter.BUSCADOR_LOCACAO_VIEW) {
                    System.out.println("Verdadeiro");
                    //buscarClienteView.setListaCodigo(clienteDAO.findByTipo("L"));
                } else {
                    System.out.println("Falso");
                    buscarClienteView.setListaCodigo(clienteDAO.findAll());
                    buscarClienteView.setListaNome(clienteDAO.findAll());
                    buscarClienteView.setListaCpf(clienteDAO.findAll());
                    buscarClienteView.setListaRg(clienteDAO.findAll());
                    buscarClienteView.setListaCnpj(clienteDAO.findAll());
                    buscarClienteView.setListaInscricaoEstadual(clienteDAO.findAll());
                }
                
                //buscarClienteView.comboDescricaoRemoveAllItens();
                //buscarClienteView.comboSerieRemoveAllItens();
                
                presenter.setTipoBusca(presenter.POR_CODIGO_STRATEGY);
                
            } else if (e.getSource() == presenter.getBuscarClienteView().getComboNomeJCombo()) {
                
                if (presenter.getBuscador() == presenter.BUSCADOR_LOCACAO_VIEW) {
                    //buscarClienteView.setListaDescricao(clienteDAO.findByTipo("C"));
                } else {
                    //buscarClienteView.setLista(clienteDAO.findAll());
                }
                
                //buscarClienteView.comboCodigoRemoveAllItens();
                //buscarClienteView.comboSerieRemoveAllItens();
                
                presenter.setTipoBusca(presenter.POR_NOME_STRATEGY);
                
            } else if (e.getSource() == presenter.getBuscarClienteView().getComboCpfJCombo()) {
                
                if (presenter.getBuscador() == presenter.BUSCADOR_LOCACAO_VIEW) {
                    //buscarClienteView.setListaSerie(clienteDAO.findByTipo("C"));
                } else {
                    //buscarClienteView.setListaSerie(clienteDAO.findAll());
                }
                
                //buscarClienteView.comboCodigoRemoveAllItens();
                //buscarClienteView.comboDescricaoRemoveAllItens();
                
                presenter.setTipoBusca(presenter.POR_CPF_STRATEGY);
                
            }
            
            else if (e.getSource() == presenter.getBuscarClienteView().getComboRgJCombo()) {
                
                if (presenter.getBuscador() == presenter.BUSCADOR_LOCACAO_VIEW) {
                    //buscarClienteView.setListaSerie(clienteDAO.findByTipo("C"));
                } else {
                    //buscarClienteView.setListaSerie(clienteDAO.findAll());
                }
                
                //buscarClienteView.comboCodigoRemoveAllItens();
                //buscarClienteView.comboDescricaoRemoveAllItens();
                
                presenter.setTipoBusca(presenter.POR_RG_STRATEGY);
                
            }
            
            else if (e.getSource() == presenter.getBuscarClienteView().getComboCnpjJCombo()) {
                
                if (presenter.getBuscador() == presenter.BUSCADOR_LOCACAO_VIEW) {
                    //buscarClienteView.setListaSerie(clienteDAO.findByTipo("C"));
                } else {
                    //buscarClienteView.setListaSerie(clienteDAO.findAll());
                }
                
                //buscarClienteView.comboCodigoRemoveAllItens();
                //buscarClienteView.comboDescricaoRemoveAllItens();
                
                presenter.setTipoBusca(presenter.POR_CNPJ_STRATEGY);
                
            }
            
            else if (e.getSource() == presenter.getBuscarClienteView().getComboInscricaoEstadualJCombo()) {
                
                if (presenter.getBuscador() == presenter.BUSCADOR_LOCACAO_VIEW) {
                    //buscarClienteView.setListaSerie(clienteDAO.findByTipo("C"));
                } else {
                    //buscarClienteView.setListaSerie(clienteDAO.findAll());
                }
                
                //buscarClienteView.comboCodigoRemoveAllItens();
                //buscarClienteView.comboDescricaoRemoveAllItens();
                
                presenter.setTipoBusca(presenter.POR_INSCRICAOESTADUAL_STRATEGY);
                
            }
            
        }
        
        @Override
        public void focusLost(FocusEvent e) {
            if (e.getSource() == presenter.getBuscarClienteView().getComboCodigoJCombo()) {
                
                //buscarClienteView.comboDescricaoRemoveAllItens();
                //buscarClienteView.comboSerieRemoveAllItens();
                
            } else if (e.getSource() == presenter.getBuscarClienteView().getComboNomeJCombo()) {
                
                //buscarClienteView.comboCodigoRemoveAllItens();
                //buscarClienteView.comboSerieRemoveAllItens();
                
            } else if (e.getSource() == presenter.getBuscarClienteView().getComboCpfJCombo()) {
                
                //buscarClienteView.comboCodigoRemoveAllItens();
                //buscarClienteView.comboDescricaoRemoveAllItens();
                
            }
        }
    }
    
    static class BuscarActionListener implements ActionListener {
        
        private BuscarClientePresenter presenter;
        
        public BuscarActionListener(BuscarClientePresenter presenter) {
            this.presenter = presenter;            
        }
        
        @Override
        public void actionPerformed(ActionEvent e) {
            presenter.getTipoBusca().execute();            
            presenter.getBuscarClienteView().dispose();
        }
    }
    
    static class SairActionListener implements ActionListener {
        
        @Override
        public void actionPerformed(ActionEvent evt) {
            System.exit(0);
        }
    }
}
